﻿$(function() {
    JSUtility.param.Options["InternalType"] = "0";
    JSUtility.param.ClassName = "OA.Bll.Project.ContractInfoPresenter";
    autoResize({ dataGrid: '#Grid', callback: Initlist });

    JSUtility.window_edit = $('#Add').window({
        iconCls: 'icon-add',
        zIndex: 1000,
        draggable: true,
        resizable: false,
        shadow: true,
        inline: true,
        modal: true,
        title: '添加合同信息',
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: true,
        width: 450,
        //height: 630,
        closed: true,
        onOpen: function() {
            $('#Add').parent().css("left", "10%");
            $('#Add').parent().next().css("left", "10%");
            $('#Add').parent().next().css("top", "10%");
            $('#Add').parent().css("top", "10%");
        }
    });
    //alert(JSUtility.window_edit_form);
    JSUtility.window_edit_title = "合同信息";
    JSUtility.window_edit_form = $('#Add').find("form");

    ComboboxInitial();
    $('#Add').show();
});
function ComboboxInitial() {
    JSHelper.comboboxData("#ContractState", '9');
    if (!self.parent.projectInfoManager) {
        JSHelper.combotreeProject('ProjectId');
    }
}


function Initlist(size) {
    if (self.parent.projectInfoManager) {        
        JSUtility.param.Options["ProjectId"] = self.parent.parent.project_id;
        JSUtility.replenish = function() {
            $("#ProjectId").val(self.parent.parent.project_id);
        };
        $("#ProjectId").attr("readonly", "readonly");
    }
    JSUtility.param.Method = "Search";
    JSUtility.grid = $('#Grid').datagrid({
        tilte: '合同基本信息',
        iconCls: 'icon-contract',
        width: size.width,
        height: size.height,
        pageSize: Math.round(size.height / 25),
        pageList: [Math.round(size.height / 25)],
        nowrap: true,
        striped: true,
        url: JSUtility.url,
        queryParams: { "json": $.toJSON(JSUtility.param) },
        sortName: 'Id',
        sortOrder: 'desc',
        idField: 'Id',
        frozenColumns: [[{ title: '编号', field: 'Id', width: 50, sortable: true}]],
        columns: [[
                            { title: '外部合同编号', field: 'OuterNum', width: 120 },
                            { title: '内部合同编号', field: 'InnerNum', width: 80 },
                            { title: '合同名称', field: 'ContractName', width: 100 },
                            { title: '项目编号', field: 'ProjectId', width: 80 },
                            { title: '项目名称', field: 'ProjectName', width: 100 },
                            { title: '合同状态', field: 'ContractState', width: 100 },
                            { title: '开始日期', field: 'StartTime', width: 100 },
                            { title: '终止日期', field: 'FinishedTime', width: 100 },
                            { title: '合同总额', field: 'ContractAmount', width: 100 },
                            { title: '合同有效金额', field: 'ContractEffectiveAmount', width: 100 },
                            { title: '支付方式', field: 'PayWay', width: 200 }
                        ]],
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        toolbar: [
                    {
                        text: '添加',
                        iconCls: 'icon-add',
                        handler: JSUtility.add
                    }, '-',
                    {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function() {
                            JSUtility.update();
                            JSHelper.conbotreeUpdateProject("ProjectId");
                        }
                    }, '-',
                    {
                        text: '删除',
                        iconCls: 'icon-remove',
                        handler: JSUtility.del
                    }, '-',
                    {
                        text: '查询',
                        iconCls: 'icon-search',
                        handler: JSUtility.search
                    }, '-',
                    {
                        text: '详细信息',
                        iconCls: 'icon-edit',
                        handler: contractsInfoOpen
                    }
                  ]
    });
}

function contractsInfoOpen() {
    var row = JSHelper.isDatagridSelected($("#Grid"));
    if (row == null) return;
    if (!self.parent.projectInfoManager) {
        self.parent.contracts_id = row.OuterNum;
        self.parent.contracts_Name = row.ContractName;
        self.parent.addTab("合同详细信息", "Project/ContractsInfoManager.htm", "icon-edit");
    } else {
        self.parent.parent.contracts_id = row.OuterNum;
        self.parent.parent.contracts_Name = row.ContractName;
        self.parent.projectInfoManager.addTab("合同详细信息", "ContractsInfoManager.htm", "icon-edit");

    }
}
